package cmd

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
	"iTP/internal/controller/hello"
	"iTP/internal/controller/user"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/api", func(group *ghttp.RouterGroup) {
				group.Middleware(ghttp.MiddlewareHandlerResponse)
				// 配置路由分组
				group.Group("/hello", func(group *ghttp.RouterGroup) {
					// 绑定"/hello"路径下的处理逻辑
					group.Bind(
						hello.NewHello(), // 创建并绑定"hello"包下的Hello实例
					)
				})
				group.Group("/user", func(group *ghttp.RouterGroup) {
					// 绑定"/user"路径下的处理逻辑
					group.Bind(
						user.New(), // 创建并绑定"user"包下的User实例
					)
				})
			})
			s.Run()
			return nil
		},
	}
)
